package com.europe.business.europebusiness.ui.fragment.base;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Map;

public abstract class BaseFragment extends Fragment {

    protected Context context;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(setLayout(), container, false);
        initView(view);
        return view;
    }

    protected abstract int setLayout();

    protected abstract void initView(View view);


    /**
     * 显示短时间的toast
     * @param toast
     */
    protected void showToastShort(String toast){
        Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
    }

    /**
     * 显示长时间的toast
     * @param toast
     */

    protected void showToastLong(String toast){
        Toast.makeText(context, toast, Toast.LENGTH_LONG).show();
    }

    /**
     * activity的跳转(不带数据)
     * @param cls
     */
    protected void startAct(Class cls){
        Intent intent = new Intent();
        intent.setClass(context, cls);
        startActivity(intent);
    }


    /**
     * activity的跳转(带包裹数据bundle)
     * @param cls
     * @param data
     */
    protected void startAct(Class cls, Bundle data){
        Intent intent = new Intent();
        intent.putExtras(data);
        intent.setClass(context, cls);
        startActivity(intent);
    }



}
